package com.wlxk.message.web.aop;

import com.wlxk.base.common.constant.WlErrEnum;
import com.wlxk.base.common.dto.WlResult;
import com.wlxk.base.common.exception.WlException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author ：wlxk
 * @since ：2022/2/17 15:36
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * -------- 通用异常处理方法 --------
     **/
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public WlResult<?> error(Exception e) {
        log.error("Exception,", e);
        return WlResult.fail(WlErrEnum.UNKNOWN);
    }

    /**
     * -------- 自定义定异常处理方法 --------
     **/
    @ExceptionHandler(WlException.class)
    @ResponseBody
    public WlResult<?> error(WlException e) {
        log.error("WlException,", e);
        return WlResult.fail(e);
    }

}
